#ifndef PARTICLESOURCE1D_LOAD_H
#define PARTICLESOURCE1D_LOAD_H

#include <vector>
#include "ParticleSource1D.h"


using namespace std;

class ParticleSource1D_Load : public ParticleSource1D
{

public:

    ParticleSource1D_Load(PicParams* params_, ParallelMPI* pmpi_, PhysicalField* fields_, vector<Species*>* vecSpecies_, ParticleSourceParameter ps_param_);

    ~ParticleSource1D_Load();



    //Method called in the main pic loop to apply collision at each timestep
    void emitLoad(int itime);


    //=================Parameters for loading particles=================
    vector<int> loadTimeStepVector;
    vector<double> load_temperatureVector;
    vector<double> load_dnVector;
    double loadDensity;
    double load_temperature;
    double load_temperature_init;
    double load_temperature_exceed;
	double load_temperature_heat;
    //load density per second [m-3 s-1]
    double load_dn;
    double load_dn_final;

    //load heat flux density = load_dn * load_temperature
    double load_dq;
    double load_dq_cell;
    int load_step;
    //Number of particles loaded in one cell at one load_step
    int load_number;
    int load_number_heat;
    double load_number_init_double;
    double load_number_final_double;
    //load_number_rem = load_step * load_dn *... - load_number
    double load_number_double;
    double load_number_rem;
    double load_number_rem_tot;

    //number density in the middle of source region
    double load_source_density;
    double load_source_density_pre;

    //MPI rank of source middle region
    int mpiRank_source_middle;
    //index of field at source middle;
    int index_source_middle;

    bool is_begin_change_dn;


private:
    double dt_ov_dx;
    double dt;
    double YZArea;

    //nominalDensity and nomPtclsPerCell is used to set the weight_const
    //weight_cosnt = nominalDensity * CellVolume / nomPtclsPerCell
    double nominalDensity;
    double nomPtclsPerCell;
    //emitting tempreature


    //========== Some variables for emitLoad method ===================

    //Parameters for "nq"
    int timeStep_checkFor_nq;
    double temperature_pre;
    double load_temperature_upLimit_factor;

    //Parameters for "dn"
    int nextTimeStep = 0;
    int nextTimeStep_index = 1;

    //values for pid control of density
    double load_dn_pid;
    double p_value;
    double i_value;
    double d_value;



};


#endif
